package com.quanyan.riding.web;

import com.github.ltsopensource.core.json.JSON;
import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.riding.entity.vo.req.ReqRidingRecord;
import com.quanyan.riding.entity.vo.req.ReqRidingTrack;
import com.quanyan.riding.entity.vo.resp.RespRidingRecordMonth;
import com.quanyan.riding.service.RidingSingleService;
import com.quanyan.riding.util.RunRidingEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xian-guo
 * @email 498152332@qq.com
 * @date 2016/8/29.
 */
@RestController
@RequestMapping(value = "api/riding")
public class RidingSingleController {

    private static final Logger LOGGER = LoggerFactory.getLogger(RidingSingleController.class);

    @Autowired
    private RidingSingleService ridingSingleService;

    /**
     * 骑行结束插入骑行详细记录
     * @param reqRidingTrack
     * @return
     */
    @RequestMapping(value = "ridingTrack",method = RequestMethod.POST)
    public APIResponse insertRidingTrack(@RequestBody(required = true) ReqRidingTrack reqRidingTrack){
        LOGGER.debug("--------------->>>>"+JSON.toJSONString(reqRidingTrack));
        if (StringUtil.isBlankOrNull(reqRidingTrack.getUserId()) || StringUtil.isBlankOrNull(reqRidingTrack.getBeginDate()) || StringUtil.isBlankOrNull(reqRidingTrack.getEndDate())){
            return APIResponse.returnFail(RunRidingEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        return ridingSingleService.insertRidingTrack(reqRidingTrack);
    }

    /**
     * 骑行生涯记录
     * @param reqRidingRecord
     * @return
     */
    @RequestMapping(value = "monthRidingRecord",method = RequestMethod.POST)
    public APIResponse<PageObj<List<RespRidingRecordMonth>>> getMonthRidingRecord(@RequestBody(required = true)ReqRidingRecord reqRidingRecord){
        if(StringUtil.isBlankOrNull(reqRidingRecord.getUserId()) || null == reqRidingRecord.getPageNum() || null == reqRidingRecord.getPageSize()){
            return APIResponse.returnFail(RunRidingEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        return ridingSingleService.getMonthRidingRecord(reqRidingRecord);
    }

}
